<?php
namespace src\lib;

use src\Curl;

/**
 * 网易严选图床
 * Class Netease
 * @package src\lib
 * @url http://you.163.com/
 */

class Netease
{   
    public function upload($path)
    {
        $data = ['file' => Curl::getCurlFile($path), 'format' => 'json'];
        $result = Curl::post('http://you.163.com/xhr/file/upload.json', $data, [
            CURLOPT_HTTPHEADER => [
                'Referer: http://you.163.com',
                'Origin: http://you.163.com',
            ],
        ]);

        $result = json_decode($result, true);
        if ($result['code'] != '200') {
            return false;
        }

        return str_replace('http://', 'https://', $result['data'][0]);
    }

}